#include "bits/stdc++.h"
#include <iterator>
using namespace std;
using ll = long long;
const int N = 200009; //1e5+5//100005

struct milk
{
	int price;
	int total;
};
milk m[N];
bool cmp(milk x,milk y)
{
	return x.price < y.price;
}
int n,mm,sum,ans;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin >> n >> mm;
	for(int i=1;i<=mm;i++)
	{
		cin >> m[i].price >> m[i].total;
	} 
	sort(m+1,m+1+mm,cmp);
	for(int i=1;i<=mm;i++)
	{
		sum += m[i].total;
		if(sum>n)
		{
			ans += (n-(sum-m[i].total))*m[i].price;
			break;
		}
		ans += m[i].price * m[i].total;
	}
	cout << ans;
	return 0;
}
